package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.aop_whh.annotation.OperateLog;
import com.cskaoyan.wordmemorize.common.constant.ResultCodeEnum;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.LevelPrivilegeDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.LevelPrivilegeCommand;
import com.cskaoyan.wordmemorize.request.LevelPrivilegePageRequest;
import com.cskaoyan.wordmemorize.service.LevelPrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/privilege")
public class PrivilegeController_whh {
    @Autowired
    LevelPrivilegeService levelPrivilegeService;

    //显示所有列表
    @GetMapping("list")
    public Result<PageDTO<LevelPrivilegeDTO>> getList(LevelPrivilegePageRequest pageRequest) {
        PageDTO<LevelPrivilegeDTO> privilegeList = levelPrivilegeService.getLevelPrivilegeList(pageRequest);
        return Result.ok(privilegeList);

    }

    //新增特权
    @OperateLog(dateType = "特权", operateType = 1)
    @PostMapping
    public Result postPrivilege(@RequestBody LevelPrivilegeCommand privilegeCommand) {
        levelPrivilegeService.addLevelPrivilege(privilegeCommand);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }

    @OperateLog(dateType = "特权", operateType = 4)
    @PutMapping
    public Result putPrivilege(@RequestBody LevelPrivilegeCommand privilegeCommand) {
        levelPrivilegeService.updateLevelPrivilege(privilegeCommand);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }

    @OperateLog(dateType = "特权", operateType = 2)
    @DeleteMapping("{id}")
    public Result deletePrivilege(@PathVariable Long id) {
        levelPrivilegeService.deleteLevelPrivilege(id);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }

    @OperateLog(dateType = "特权", operateType = 3)
    @DeleteMapping("batch")
    public Result deletePrivilegeList(@RequestBody BatchDeleteCommand batchDeleteCommand) {
        levelPrivilegeService.batchDeleteLevelPrivilege(batchDeleteCommand);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }
}
